package com.yuven.appframework.util;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

import com.yuven.appframework.R;


/**
 * Created by cxf on 2017/8/8.
 */

public class DialogUtil {
    public static final int INPUT_TYPE_TEXT = 0;
    public static final int INPUT_TYPE_NUMBER = 1;
    public static final int INPUT_TYPE_NUMBER_PASSWORD = 2;
    public static final int INPUT_TYPE_TEXT_PASSWORD = 3;

    //第三方登录的时候用显示的dialog
//    public static Dialog loginAuthDialog(Context context) {
//        Dialog dialog = new Dialog(context, R.style.dialog);
//        dialog.setContentView(R.layout.dialog_login_loading);
//        dialog.setCancelable(true);
//        dialog.setCanceledOnTouchOutside(false);
//        return dialog;
//    }
   private  static   Dialog dialog= null;


    public static Dialog getInstance(Context context) {
        if (dialog == null) {
            synchronized (DialogUtil.class) {
                if (dialog == null) {
                    dialog = new Dialog(context, R.style.core_dialog);
                }
            }
        }
        return dialog;
    }
    /**
     * 用于网络请求等耗时操作的LoadingDialog
     */
    public static Dialog loadingDialog(Context context, String text) {
        dialog = new Dialog(context, R.style.core_dialog);
        dialog.setContentView(R.layout.core_dialog_loading);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        if (!TextUtils.isEmpty(text)) {
            TextView titleView = (TextView) dialog.findViewById(R.id.text);
            if (titleView != null) {
                titleView.setText(text);
            }
        }
        return dialog;
    }

    public static Dialog loadingDialog(Context context) {
        return loadingDialog(context, "");
    }
}
